package com.woniuxy.member.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.member.app.apiImpl.util.RequestUtil;
import com.woniuxy.member.client.CommentQueryClient;
import com.woniuxy.member.client.param.CommentInfoSearchParam;
import com.woniuxy.member.client.param.CommentInfoSearchParams;
import com.woniuxy.member.client.result.CommentInfoClientDto;
import com.woniuxy.member.service.CommentInfoService;
import com.woniuxy.member.service.dto.CommentInfoDto;
import com.woniuxy.member.service.param.CommentInfoSearchServiceParam;
import com.woniuxy.member.service.param.CommentInfoSearchServiceParams;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RequestMapping("/member")
@RestController
public class CommentQueryApiImpl implements CommentQueryClient {
    @Autowired
    private CommentInfoService commentInfoService;
    @Log("用户查询评论")
    @Override
    public Result<WoniuPage<CommentInfoClientDto>> getAllScoreCommentInfo(@Valid CommentInfoSearchParam commentInfoSearchParam) {
        if (commentInfoSearchParam.getPageIndex()==null){
            commentInfoSearchParam.setPageIndex(1);
        }
        if (commentInfoSearchParam.getPageSize()==null){
            commentInfoSearchParam.setPageSize(3);
        }
        CommentInfoSearchServiceParams commentInfoSearchServiceParams = BeanUtil.toBean(commentInfoSearchParam, CommentInfoSearchServiceParams.class);
        commentInfoSearchServiceParams.setStoreId(RequestUtil.getStoreId());
        commentInfoSearchServiceParams.setMemberId(RequestUtil.getMemberId());
        WoniuPage<CommentInfoDto> list = commentInfoService.getAllScoreCommentInfo(commentInfoSearchServiceParams);
        WoniuPage<CommentInfoClientDto> woniuPage = BeanUtil.toBean(list,WoniuPage.class);
        return Result.success(woniuPage);
    }

    @Override
    public Result<WoniuPage<CommentInfoClientDto>> getStoreCommentInfo(@Valid CommentInfoSearchParams commentInfoSearchParams) {
        if (commentInfoSearchParams.getPageIndex()==null){
            commentInfoSearchParams.setPageIndex(1);
        }
        if (commentInfoSearchParams.getPageSize()==null){
            commentInfoSearchParams.setPageSize(3);
        }
        CommentInfoSearchServiceParam commentInfoSearchServiceParam = BeanUtil.toBean(commentInfoSearchParams, CommentInfoSearchServiceParam.class);
        WoniuPage<CommentInfoDto> woniuPage = commentInfoService.getStoreCommentInfo(commentInfoSearchServiceParam);
        WoniuPage<CommentInfoClientDto> list = BeanUtil.toBean(woniuPage,WoniuPage.class);
        return Result.success(list);
    }
}
